/**
 * Copyright 2018 人人开源 http://www.renren.io <p> Licensed under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance with the License. You may obtain a
 * copy of the License at <p> http://www.apache.org/licenses/LICENSE-2.0 <p> Unless required by
 * applicable law or agreed to in writing, software distributed under the License is distributed on
 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See
 * the License for the specific language governing permissions and limitations under the License.
 */

package com.teorange.magic.bottle.api.plugins.oss.cloud;

import cn.teorange.framework.core.utils.DateUtils;
import java.io.InputStream;
import java.util.Date;
import java.util.UUID;
import org.apache.commons.lang.StringUtils;

/**
 * 云存储(支持七牛、阿里云、腾讯云、又拍云)
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2017-03-25 14:58
 */
public abstract class CloudStorageService {

  /**
   * 云存储配置信息
   */
  CloudStorageConfig config;

  /**
   * 文件路径
   *
   * @param prefix 前缀
   * @param suffix 后缀
   * @return 返回上传路径
   */
  public String getPath(String prefix, String suffix) {
    //生成uuid
    String uuid = UUID.randomUUID().toString().replaceAll("-", "");
    //文件路径
    String path = DateUtils.format(new Date(), "yyyyMMdd") + "/" + uuid;

    if (StringUtils.isNotBlank(prefix)) {
      path = prefix + "/" + path;
    }

    return path + suffix;
  }

  /**
   * 文件上传
   *
   * @param data 文件字节数组
   * @param path 文件路径，包含文件名
   * @return 返回http地址
   */
  public abstract String upload(byte[] data, String path);

  /**
   * 文件上传
   *
   * @param data 文件字节数组
   * @param suffix 后缀
   * @return 返回http地址
   */
  public abstract String uploadSuffix(byte[] data, String suffix);

  /**
   * 文件上传
   *
   * @param inputStream 字节流
   * @param path 文件路径，包含文件名
   * @return 返回http地址
   */
  public abstract String upload(InputStream inputStream, String path);

  /**
   * 文件上传
   *
   * @param inputStream 字节流
   * @param suffix 后缀
   * @return 返回http地址
   */
  public abstract String uploadSuffix(InputStream inputStream, String suffix);


  /**
   * 获取token
   */
  public abstract String getToken(long expireTime);

}
